package com.niknik.woody.rest;

import com.niknik.woody.rest.response.WResponse;
import com.niknik.woody.rest.schema.RespMsg;
import com.niknik.woody.rest.schema.RespStatus;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

/**
 * User: yoda
 * Date: 04.12.11
 * Time: 14:30
 */
public class RespHelper {

  public static void assertClientMsg(RespMsg msg, WResponse resp) {
    assertThat(resp.getMsgCode(), is(msg.getCode()));
  }

  public static void assertRespStatus(RespStatus status, WResponse resp) {
    assertThat(resp.getStatusCode(), is(status.getCode()));
  }

  public static void assertBadRequest(WResponse resp) {
    assertRespStatus(RespStatus.ERR, resp);
    assertClientMsg(RespMsg.BAD_REQUEST, resp);
  }

  public static void assertInternalErr(WResponse resp) {
    assertRespStatus(RespStatus.ERR, resp);
    assertClientMsg(RespMsg.INTERNAL_ERR, resp);
  }

  public static void assertSuccess(WResponse resp) {
    assertRespStatus(RespStatus.SUCCESS, resp);
    assertClientMsg(RespMsg.SUCCESS, resp);
  }

  public static void assertErr(WResponse resp, RespMsg msg) {
    assertRespStatus(RespStatus.ERR, resp);
    assertClientMsg(RespMsg.ROOM_NOT_REACHABLE, resp);
  }

  public static void assertGameErr(WResponse resp, Integer msgCode) {
    assertRespStatus(RespStatus.ERR, resp);
    assertThat(resp.getMsgCode(), is(msgCode));
  }

  public static void assertGameFatal(WResponse resp, Integer msgCode) {
    assertRespStatus(RespStatus.FATAL, resp);
    assertThat(resp.getMsgCode(), is(msgCode));
  }
}